var screen = {
    colorDepth: 24,
    height: 1080,
    pixelDepth: 24,
    width: 1920
}
var Fingerprint = function(options) {
        var nativeForEach = Array.prototype.forEach
          , nativeMap = Array.prototype.map;
        this.each = function(obj, iterator, context) {
            if (null !== obj)
                if (nativeForEach && obj.forEach === nativeForEach)
                    obj.forEach(iterator, context);
                else if (obj.length === +obj.length) {
                    for (var i = 0, l = obj.length; i < l; i++)
                        if (iterator.call(context, obj[i], i, obj) === {})
                            return
                } else
                    for (var key in obj)
                        if (obj.hasOwnProperty(key) && iterator.call(context, obj[key], key, obj) === {})
                            return
        }
        ,
        this.map = function(obj, iterator, context) {
            var results = [];
            return null == obj ? results : nativeMap && obj.map === nativeMap ? obj.map(iterator, context) : (this.each(obj, function(value, index, list) {
                results[results.length] = iterator.call(context, value, index, list)
            }),
            results)
        }
        ,
        "object" == typeof options ? (this.hasher = options.hasher,
        this.screen_resolution = options.screen_resolution,
        this.canvas = options.canvas,
        this.ie_activex = options.ie_activex) : "function" == typeof options && (this.hasher = options)
    }

var _Fingerprint = function(options){
    Fingerprint.prototype = {
        get: function() {
            var keys = [];
            return keys.push(navigator.userAgent),
            keys.push(navigator.language),
            keys.push(screen.colorDepth),
            this.screen_resolution && void 0 !== this.getScreenResolution() && keys.push(this.getScreenResolution().join("x")),
            keys.push((new Date).getTimezoneOffset()),
            keys.push(this.hasSessionStorage()),
            keys.push(this.hasLocalStorage()),
            keys.push(!!window.indexedDB),
            document.body ? keys.push(typeof document.body.addBehavior) : keys.push("undefined"),
            keys.push(typeof window.openDatabase),
            keys.push(navigator.cpuClass),
            keys.push(navigator.platform),
            keys.push(navigator.doNotTrack),
            keys.push(this.getPluginsString()),
            this.canvas && this.isCanvasSupported() && keys.push(this.getCanvasFingerprint()),
            this.hasher ? this.hasher(keys.join("###"), 31) : this.murmurhash3_32_gc(keys.join("###"), 31)
        },
        murmurhash3_32_gc: function(key, seed) {
            for (var h1b, k1, remainder = 3 & key.length, bytes = key.length - remainder, h1 = seed, c1 = 3432918353, c2 = 461845907, i = 0; i < bytes; )
                k1 = 255 & key.charCodeAt(i) | (255 & key.charCodeAt(++i)) << 8 | (255 & key.charCodeAt(++i)) << 16 | (255 & key.charCodeAt(++i)) << 24,
                ++i,
                h1 = 27492 + (65535 & (h1b = 5 * (65535 & (h1 = (h1 ^= k1 = (65535 & (k1 = (k1 = (65535 & k1) * c1 + (((k1 >>> 16) * c1 & 65535) << 16) & 4294967295) << 15 | k1 >>> 17)) * c2 + (((k1 >>> 16) * c2 & 65535) << 16) & 4294967295) << 13 | h1 >>> 19)) + ((5 * (h1 >>> 16) & 65535) << 16) & 4294967295)) + ((58964 + (h1b >>> 16) & 65535) << 16);
            switch (k1 = 0,
            remainder) {
            case 3:
                k1 ^= (255 & key.charCodeAt(i + 2)) << 16;
            case 2:
                k1 ^= (255 & key.charCodeAt(i + 1)) << 8;
            case 1:
                h1 ^= k1 = (65535 & (k1 = (k1 = (65535 & (k1 ^= 255 & key.charCodeAt(i))) * c1 + (((k1 >>> 16) * c1 & 65535) << 16) & 4294967295) << 15 | k1 >>> 17)) * c2 + (((k1 >>> 16) * c2 & 65535) << 16) & 4294967295
            }
            return h1 ^= key.length,
            h1 = 2246822507 * (65535 & (h1 ^= h1 >>> 16)) + ((2246822507 * (h1 >>> 16) & 65535) << 16) & 4294967295,
            h1 = 3266489909 * (65535 & (h1 ^= h1 >>> 13)) + ((3266489909 * (h1 >>> 16) & 65535) << 16) & 4294967295,
            (h1 ^= h1 >>> 16) >>> 0
        },
        hasLocalStorage: function() {
            try {
                return !!window.localStorage
            } catch (e) {
                return !0
            }
        },
        hasSessionStorage: function() {
            try {
                return !!window.sessionStorage
            } catch (e) {
                return !0
            }
        },
        isCanvasSupported: function() {
            var elem = document.createElement("canvas");
            return false;
            // return !(!elem.getContext || !elem.getContext("2d"))
        },
        isIE: function() {
            return "Microsoft Internet Explorer" === navigator.appName || !("Netscape" !== navigator.appName || !/Trident/.test(navigator.userAgent))
        },
        getPluginsString: function() {
            return this.isIE() && this.ie_activex ? this.getIEPluginsString() : this.getRegularPluginsString()
        },
        getRegularPluginsString: function() {
            return this.map(navigator.plugins, function(p) {
                var mimeTypes = this.map(p, function(mt) {
                    return [mt.type, mt.suffixes].join("~")
                }).join(",");
                return [p.name, p.description, mimeTypes].join("::")
            }, this).join(";")
        },
        getIEPluginsString: function() {
            if (window.ActiveXObject)
                return this.map(["ShockwaveFlash.ShockwaveFlash", "AcroPDF.PDF", "PDF.PdfCtrl", "QuickTime.QuickTime", "rmocx.RealPlayer G2 Control", "rmocx.RealPlayer G2 Control.1", "RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)", "RealVideo.RealVideo(tm) ActiveX Control (32-bit)", "RealPlayer", "SWCtl.SWCtl", "WMPlayer.OCX", "AgControl.AgControl", "Skype.Detection"], function(name) {
                    try {
                        return new ActiveXObject(name),
                        name
                    } catch (e) {
                        return null
                    }
                }).join(";");
            return ""
        },
        getScreenResolution: function() {
            return [screen.height, screen.width]
        },
        getCanvasFingerprint: function() {
            var canvas = document.createElement("canvas")
              , ctx = canvas.getContext("2d")
              , txt = "http://valve.github.io";
            return ctx.textBaseline = "top",
            ctx.font = "14px 'Arial'",
            ctx.textBaseline = "alphabetic",
            ctx.fillStyle = "#f60",
            ctx.fillRect(125, 1, 62, 20),
            ctx.fillStyle = "#069",
            ctx.fillText(txt, 2, 15),
            ctx.fillStyle = "rgba(102, 204, 0, 0.7)",
            ctx.fillText(txt, 4, 17),
            canvas.toDataURL()
        }
    };
    return new Fingerprint(options)
}

function get_accs_device() {
    var tabId = Math.floor(899 * Math.random() + 100);
    var browserId = _Fingerprint({
        screen_resolution: !0,
        canvas: !0
    }).get()
    return  browserId + "_" + tabId
}

function get_window_id() {
    var _tabId = Math.floor(899 * Math.random() + 100);
    var _browserId = _Fingerprint({
        screen_resolution: !0,
        canvas: !0
    }).get()
    _browserId = _browserId.toString().substr(0, 11)
    _browserId += new Array(11 - _browserId.length).join("0")
    return  "".concat(_browserId, "_").concat(_tabId)
}

module.exports = function(path, controller) {
	// key 可以是任何值只要不重复就可以
	controller[path] = {get_window_id}
}